package com.sudu.controller;

import com.sudu.exception.BusinessException;
import com.sudu.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex) {
        // 记录日志
        // 发送消息给运维
        // 发送邮件给开发人员
        ex.printStackTrace();
        System.out.println("异常Exception");
        return new Result(Code.SYSTEM_UKN_ERR,null,"系统繁忙，请稍后再试") ;
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex) {
        // 记录日志
        // 发送消息给运维
        // 发送邮件给开发人员
        ex.printStackTrace();
        System.out.println("异常SystemException");
        return new Result(ex.getCode(),null ,ex.getMessage()) ;
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex) {

        ex.printStackTrace();
        System.out.println("异常BusinessException");
        return new Result(ex.getCode(),null ,ex.getMessage()) ;
    }

}
